

const mongoose = require('mongoose');

var express = require('express')
// 注意这里的声明
var roles = express()



const {createResponse}= require("../../util/createResponse/index");
const {businessCodes}= require("../../code/businessCodes/index");
const { role_service } = require('../../service/impl/role_service/index');



//#region   角色
roles.post('/post/role/add', async (req,res) => {


  let result
  try {
    let  news  = req.body.news
    result =  await role_service.getIns().create(news)
  } catch (error) {
    console.log(error);
    createResponse(res,500,businessCodes.b2)
    return
  }
    createResponse(res,200,businessCodes.b1,result)
  })

// 根据id删除
roles.post('/post/role/delete', async (req,res) => {
  let result
  try {
    let  id  = req.body.conditions.id
    result =  await role_service.getIns().findByIdAndDelete(id)
  } catch (error) {
    console.log(error);
    createResponse(res,500,businessCodes.b2)
    return
  }
    createResponse(res,200,businessCodes.b1,result)
  })

// 根据id,修改
roles.post('/post/role/update', async (req,res) => {
  console.log(req.body,555);
  let result
  try {
    let  id  = req.body.conditions.id
    let updates = req.body.updates
    result =  await role_service.getIns().findByIdAndUpdate(id,updates)
  } catch (error) {
    console.log(error);
    createResponse(res,500,businessCodes.b2)
    return
  }
    createResponse(res,200,businessCodes.b1,result)
  })

// 查询所有
roles.post('/post/role/query', async (req,res) => {
  let result
  let fills ={
    "key1":{
      "path":"roleAuths_arr.auth_ref"
    },
    "key2":{
      "path":"appAuths.auth_ref"
    },
    "key3":{
      "path":"teamAuths.auth_ref"
    }
  }
  try {
    result =  await role_service.getIns().find(null,null,fills)
  } catch (error) {
    console.log(error);
    createResponse(res,500,businessCodes.b2)
    return
  }
    createResponse(res,200,businessCodes.b1,result)
  })


//#endregion
  
  
  
  //#endregion
  

  module.exports= roles 